#!/bin/bash

SUDO="sudo "
if [[ $(id -u) -eq 0 ]]; then SUDO=""; fi

mkdir -p $HOME/.config
mkdir -p $HOME/.local/share

$SUDO apt install python3 python3-pip python3-venv xclip fd-find ripgrep lldb-15 -y

mkdir -p ~/.pip && cat << EOF | tee ~/.pip/pip.conf
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host = pypi.mirrors.ustc.edu.cn
EOF

if [[ ! -d /root/.pip ]]; then $SUDO cp -r ~/.pip /root/; fi

if [[ -f /usr/lib/python3.11/EXTERNALLY-MANAGED ]]; then
    $SUDO mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.bak
fi

$SUDO pip3 install neovim debugpy

if [ ! -d $HOME/.config/nvim ]; then
  git clone https://gitee.com/wyanlord/nvim.git $HOME/.config/nvim
fi

if [ ! -d $HOME/.local/share/nvim ]; then
  git clone https://gitee.com/wyanlord/nvim-local.git $HOME/.local/share/nvim
  cd $HOME/.local/share/nvim/
  ./release.sh
fi

if [ ! -f /usr/bin/nvim ]; then
  cd $HOME/.local/share/nvim/
  $SUDO tar -zxvf nvim-linux64.tar.gz -C /usr --strip-components=1
fi

if [ ! -f /usr/bin/tree-sitter ]; then
  cd $HOME/.local/share/nvim/
  $SUDO tar -zxvf tree-sitter.tar.gz -C /usr/bin
fi

if [ ! -f /usr/local/bin/lazygit ]; then
  cd $HOME/.local/share/nvim/
  $SUDO tar -zxvf lazygit.tar.gz -C /usr/bin
fi
